package com.tos.second.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tos.second.common.Result.Result;
import com.tos.second.dto.OrdersDto;
import com.tos.second.entity.Goods;
import com.tos.second.service.OrdersService;
import com.tos.second.vo.OrdersHistoryVo;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.jaxb.SpringDataJaxb;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/orders")

@Slf4j
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    /**
     * 用户下单
     * @return
     */
//    @PostMapping("/submit")
//    public Result<String> submit(@RequestBody OrdersDto ordersDto) {
//        log.info("用户下单");
//        ordersService.submit(ordersDto);
//        return Result.success("用户下单");
//    }

    /**
     * 获取历史订单
     * @return
     */
    @GetMapping("/getHistoryOrders")

    public Result<List<OrdersHistoryVo>> getOrdersHistory() {
        log.info("获取历史订单");
        List<OrdersHistoryVo> ordersHistoryVoList = ordersService.getOrdersHistory();
        return Result.success(ordersHistoryVoList);
    }

    /**
     * 删除订单
     * @return
     */
    @DeleteMapping("/deleteOrder/{id}")
    public Result<String> deleteOrder(@PathVariable Long id) {
        log.info("删除订单");
        ordersService.deleteOrder(id);
        return Result.success("删除订单成功");
    }
    @GetMapping("/getSellerOrders")
    public Result<List<OrdersHistoryVo>> getSellerOrders() {
        log.info("获取商家订单");
        List<OrdersHistoryVo> ordersHistoryVoList = ordersService.getSellerOrders();
        return Result.success(ordersHistoryVoList);
    }
}
